
<?php

$currentPage = $_SERVER["PHP_SELF"];

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE infinitus_campannas SET titulo=%s, pais=%s, minombre=%s, micorreo=%s, url_redirigir_suscribir=%s, niveles=%s, smtp_servidor=%s, smtp_puerto=%s, smtp_usuario=%s, smtp_clave=%s, smtp_usar_ssl=%s, html_correo_inicial=%s WHERE idcampanna=%s",
                       GetSQLValueString($_POST['titulo'], "text"),
                       GetSQLValueString($_POST['pais'], "text"),
                       GetSQLValueString($_POST['minombre'], "text"),
                       GetSQLValueString($_POST['micorreo'], "text"),
                       GetSQLValueString($_POST['url_redirigir_suscribir'], "text"),
                       GetSQLValueString($_POST['niveles'], "int"),
                       GetSQLValueString($_POST['smtp_servidor'], "text"),
                       GetSQLValueString($_POST['smtp_puerto'], "text"),
                       GetSQLValueString($_POST['smtp_usuario'], "text"),
                       GetSQLValueString($_POST['smtp_clave'], "text"),
                       GetSQLValueString($_POST['smtp_usar_ssl'], "int"),
                       GetSQLValueString($_POST['html_correo_inicial'], "text"),
                       GetSQLValueString($_POST['idcampanna'], "int"));

  mysql_select_db($database_Infinitus, $Infinitus);
  $Result1 = mysql_query($updateSQL, $Infinitus) or die(mysql_error());
}

$colname_rsCampanna = "-1";
if (isset($_GET['idcampanna'])) {
  $colname_rsCampanna = $_GET['idcampanna'];
}
mysql_select_db($database_Infinitus, $Infinitus);
$query_rsCampanna = sprintf("SELECT * FROM infinitus_campannas WHERE idcampanna = %s", GetSQLValueString($colname_rsCampanna, "int"));
$rsCampanna = mysql_query($query_rsCampanna, $Infinitus) or die(mysql_error());
$row_rsCampanna = mysql_fetch_assoc($rsCampanna);
$totalRows_rsCampanna = mysql_num_rows($rsCampanna);

$maxRows_rsCorreos = 10;
$pageNum_rsCorreos = 0;
if (isset($_GET['pageNum_rsCorreos'])) {
  $pageNum_rsCorreos = $_GET['pageNum_rsCorreos'];
}
$startRow_rsCorreos = $pageNum_rsCorreos * $maxRows_rsCorreos;

$colname_rsCorreos = "-1";
if (isset($_GET['idcampanna'])) {
  $colname_rsCorreos = $_GET['idcampanna'];
}
mysql_select_db($database_Infinitus, $Infinitus);
$query_rsCorreos = sprintf("SELECT * FROM infinitus_correos WHERE idcampanna = %s ORDER BY idcorreo ", GetSQLValueString($colname_rsCorreos, "int"));
$query_limit_rsCorreos = sprintf("%s LIMIT %d, %d", $query_rsCorreos, $startRow_rsCorreos, $maxRows_rsCorreos);
$rsCorreos = mysql_query($query_limit_rsCorreos, $Infinitus) or die(mysql_error());
$row_rsCorreos = mysql_fetch_assoc($rsCorreos);

if (isset($_GET['totalRows_rsCorreos'])) {
  $totalRows_rsCorreos = $_GET['totalRows_rsCorreos'];
} else {
  $all_rsCorreos = mysql_query($query_rsCorreos);
  $totalRows_rsCorreos = mysql_num_rows($all_rsCorreos);
}
$totalPages_rsCorreos = ceil($totalRows_rsCorreos/$maxRows_rsCorreos)-1;

$queryString_rsCorreos = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rsCorreos") == false && 
        stristr($param, "totalRows_rsCorreos") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rsCorreos = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rsCorreos = sprintf("&totalRows_rsCorreos=%d%s", $totalRows_rsCorreos, $queryString_rsCorreos);

?>
<div>
  <?php if ($totalRows_rsCampanna == 0) { // Show if recordset empty ?>
    Aun no existen correos en este campannas
  <?php } // Show if recordset empty ?>
<form name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Titulo:</td>
      <td><input name="titulo" type="text" disabled="disabled" value="<?php echo htmlentities($row_rsCampanna['titulo'], ENT_COMPAT, ''); ?>" size="32" readonly="readonly" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Pais:</td>
      <td><input name="pais" type="text" disabled="disabled" value="<?php echo htmlentities($row_rsCampanna['pais'], ENT_COMPAT, ''); ?>" size="32" readonly="readonly" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Minombre:</td>
      <td><input name="minombre" type="text" disabled="disabled" value="<?php echo htmlentities($row_rsCampanna['minombre'], ENT_COMPAT, ''); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Micorreo:</td>
      <td><input name="micorreo" type="text" disabled="disabled" value="<?php echo htmlentities($row_rsCampanna['micorreo'], ENT_COMPAT, ''); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Url_redirigir_suscribir:</td>
      <td><input name="url_redirigir_suscribir" type="text" disabled="disabled" value="<?php echo htmlentities($row_rsCampanna['url_redirigir_suscribir'], ENT_COMPAT, ''); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Niveles:</td>
      <td><input name="niveles" type="text" disabled="disabled" value="<?php echo htmlentities($row_rsCampanna['niveles'], ENT_COMPAT, ''); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Smtp_servidor:</td>
      <td><input name="smtp_servidor" type="text" disabled="disabled" value="<?php echo htmlentities($row_rsCampanna['smtp_servidor'], ENT_COMPAT, ''); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Smtp_puerto:</td>
      <td><input name="smtp_puerto" type="text" disabled="disabled" value="<?php echo htmlentities($row_rsCampanna['smtp_puerto'], ENT_COMPAT, ''); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Smtp_usuario:</td>
      <td><input name="smtp_usuario" type="text" disabled="disabled" value="<?php echo htmlentities($row_rsCampanna['smtp_usuario'], ENT_COMPAT, ''); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Smtp_clave:</td>
      <td><input name="smtp_clave" type="text" disabled="disabled" value="<?php echo htmlentities($row_rsCampanna['smtp_clave'], ENT_COMPAT, ''); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Smtp_usar_ssl:</td>
      <td><input name="smtp_usar_ssl" type="text" disabled="disabled" value="<?php echo htmlentities($row_rsCampanna['smtp_usar_ssl'], ENT_COMPAT, ''); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Correo_inicial:</td>
      <td><input name="html_correo_inicial" type="text" disabled="disabled" value="<?php echo htmlentities($row_rsCampanna['html_correo_inicial'], ENT_COMPAT, ''); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><a href="campannas_modificar.php?idcampanna=<?php echo $row_rsCampanna['idcampanna']; ?>" target="_self">Modificar</a></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1" />
  <input type="hidden" name="idcampanna" value="<?php echo $row_rsCampanna['idcampanna']; ?>" /><?php if ($totalRows_rsCampanna > 0) { // Show if recordset not empty ?>
    <p><a href="campannas_listado_vista.php" target="_self">Regresar a listado de autocampannases</a></p>
    <p><a href="suscriptores_listados_vista.php?idcampanna=<?php echo $row_rsCampannas['idcampanna']; ?>" target="_self">Mostrar Suscriptores</a></p>

	<?php include("correos_menu_inicial.php"); ?>
    <table border="1">
    <tr>
      <td>idcampannas</td>
      <td>idcorreo</td>
      <td>asunto</td>
      <td>secuencia_meses</td>
      <td>secuencia_semanas</td>
      <td>secuencia_dias</td>
      <td>secuencia_horas</td>
      <td>secuencia_minutos</td>
      <td>absoluto_dia</td>
      <td>absoluto_horas</td>
      <td>absoluto_minutos</td>
    </tr>
    <?php do { ?>
      <tr>
        <td><?php echo $row_rsCorreos['idcampanna']; ?></td>
        <td><a href="correos_modificar_vista.php?idcorreo=<?php echo $row_rsCorreos['idcorreo']; ?>" target="_self">Modificar</a><a href="correos_eliminar_confirmar_vista.php?idcorreo=<?php echo $row_rsCorreos['idcorreo']; ?>&amp;idcampanna=<?php echo $row_rsCorreos['idcampanna']; ?>" target="_self">Eliminar</a></td>
        <td><?php echo $row_rsCorreos['asunto']; ?></td>
        <td><?php echo $row_rsCorreos['secuencia_meses']; ?></td>
        <td><?php echo $row_rsCorreos['secuencia_semanas']; ?></td>
        <td><?php echo $row_rsCorreos['secuencia_dias']; ?></td>
        <td><?php echo $row_rsCorreos['secuencia_horas']; ?></td>
        <td><?php echo $row_rsCorreos['secuencia_minutos']; ?></td>
        <td><?php echo $row_rsCorreos['absoluto_dia']; ?></td>
        <td><?php echo $row_rsCorreos['absoluto_horas']; ?></td>
        <td><?php echo $row_rsCorreos['absoluto_minutos']; ?></td>
      </tr>
      <?php } while ($row_rsCorreos = mysql_fetch_assoc($rsCorreos)); ?>
  </table>
  <table width="439" border="0">
    <tr>
      <td><?php if ($pageNum_rsCorreos > 0) { // Show if not first page ?>
            <a href="<?php printf("%s?pageNum_rsCorreos=%d%s", $currentPage, 0, $queryString_rsCorreos); ?>">First</a>
            <?php } // Show if not first page ?></td>
      <td><?php if ($pageNum_rsCorreos > 0) { // Show if not first page ?>
            <a href="<?php printf("%s?pageNum_rsCorreos=%d%s", $currentPage, max(0, $pageNum_rsCorreos - 1), $queryString_rsCorreos); ?>">Previous</a>
            <?php } // Show if not first page ?></td>
      <td><?php if ($pageNum_rsCorreos < $totalPages_rsCorreos) { // Show if not last page ?>
            <a href="<?php printf("%s?pageNum_rsCorreos=%d%s", $currentPage, min($totalPages_rsCorreos, $pageNum_rsCorreos + 1), $queryString_rsCorreos); ?>">Next</a>
            <?php } // Show if not last page ?></td>
      <td><?php if ($pageNum_rsCorreos < $totalPages_rsCorreos) { // Show if not last page ?>
            <a href="<?php printf("%s?pageNum_rsCorreos=%d%s", $currentPage, $totalPages_rsCorreos, $queryString_rsCorreos); ?>">Last</a>
            <?php } // Show if not last page ?></td>
    </tr>
  </table>
  <?php } // Show if recordset not empty ?>
</form>
</div>

<p>
Records <?php echo ($startRow_rsCorreos + 1) ?> to <?php echo min($startRow_rsCorreos + $maxRows_rsCorreos, $totalRows_rsCorreos) ?> of <?php echo $totalRows_rsCorreos ?></p>
<?php include("correos_menu_inicial.php"); ?>

<?php
mysql_free_result($rsCampanna);
mysql_free_result($rsCorreos);
?>